#!/bin/bash
MYSQL_USER=caogenadmin
MYSQL_PASSWORD=00000000
MYSQL_SERVER=caogentest.mysql.rds.aliyuncs.com
MYSQL_PORT=3306
BACKFOLDER=/data/databackup
FILENAME=`date +%Y-%m-%d-%H`.sql
if [[ ! -x "$BACKFOLDER/cgtz_db" ]]; then
	sudo mkdir -p "$BACKFOLDER/cgtz_db"
	sudo chmod -R 777 "$BACKFOLDER/cgtz_db"
fi
if [[ ! -x "$BACKFOLDER/cgjr_db" ]]; then
	sudo mkdir -p "$BACKFOLDER/cgjr_db"
	sudo chmod -R 777 "$BACKFOLDER/cgjr_db"
fi

echo "BEGIN TO BACK UP CGJR DB"
mysqldump -u$MYSQL_USER -p$MYSQL_PASSWORD -h$MYSQL_SERVER -P$MYSQL_PORT cgjr>$BACKFOLDER/cgjr_db/$FILENAME
echo "BEGIN TO BACK UP CGTZ DB"
mysqldump -u$MYSQL_USER -p$MYSQL_PASSWORD -h$MYSQL_SERVER -P$MYSQL_PORT caogen>$BACKFOLDER/cgtz_db/$FILENAME